@file:Suppress("ObjectPropertyName", "NonAsciiCharacters")

package org.glavo.bot.data

import kotlinx.serialization.json.*
import java.net.NetworkInterface
import java.util.*

object Config {
    private val config: JsonObject = Json.parseToJsonElement(Data.readResourceAsText("secret/Config.json")).jsonObject

    val qq = config["qq"]!!.jsonPrimitive.long

    val password: String
        get() = String(Base64.getDecoder().decode(config["password"]!!.jsonPrimitive.content), Charsets.UTF_8)

    val rconPassword = config["rconPassword"]!!.jsonPrimitive.content

    val MainGroupID = config["MainGroupID"]!!.jsonPrimitive.long
    val CommandGroupID = config["CommandGroupID"]!!.jsonPrimitive.long

    val ServerIP: String = run {
        val iip = config["IntranetIP"]!!.jsonPrimitive.content
        for (networkInterface in NetworkInterface.getNetworkInterfaces()) {
            for (interfaceAddress in networkInterface.interfaceAddresses) {
                if (interfaceAddress.address.hostAddress == iip) {
                    return@run "127.0.0.1"
                }
            }
        }
        iip
    }

    val MainDomain: String = config["MainDomain"]!!.jsonPrimitive.content
    val SubDomain: String = config["SubDomain"]!!.jsonPrimitive.content
    val ServerDomain: String = "$SubDomain.$MainDomain"


    val AccessKeyId: String = config["AccessKeyId"]!!.jsonPrimitive.content
    val AccessSecret: String = config["AccessSecret"]!!.jsonPrimitive.content

    val Post: String = config["Post"]!!.jsonPrimitive.content

    val isOnMCServer = ServerIP == "127.0.0.1"

    val IPMIAddress = config["IPMIAddress"]!!.jsonPrimitive.content
    val IPMIUserName = config["IPMIUserName"]!!.jsonPrimitive.content
    val IPMIUserPassword = config["IPMIUserPassword"]!!.jsonPrimitive.content
}